$(function  () {

    $.post(
        ipurl+'/role/get',
        function(result) {
            if(result.code == 200){
                var menulist = result.data.results;
                var menuhtml = '<option value="0"></option>';
                for(var i=0;i<menulist.length;i++){
                    menuhtml+='<option value="'+menulist[i].ID+'">';
                    menuhtml+=menulist[i].name;
                    menuhtml+='</option>';
                }
                $("#type").html(menuhtml);
                //cookie数据赋值
                var id = $.cookie("uid");
                var name = $.cookie("uname");
                var address = $.cookie("upwd");
                var parent = $.cookie("utype");
                $("#name").val(name);
                $("#pwd").val(address);
                $("#type").val(parent);
            }
        }
    );


    layui.use('form', function(){
        var form = layui.form();
        //监听提交
        form.on('submit(edit)', function(data){
              var name1 = $("#name").val();
              var pwd1 = $("#pwd").val();
              var type1 = $("#type").val();

              $.ajax({
                url: ipurl+'/user/update',
                data: {
                    id:id,
                    name: name1,
                    pwd: pwd1,
                    type: type1
                },
                type: "POST",
                //dataType: "json",
                complete: function(data) {
                }
            });
            x_admin_close();
            top.location.reload();
          });
    });

})
